package com.example.springboot_demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.springboot_demo.entity.Goods;
import com.example.springboot_demo.mapper.GoodsMapper;
import com.example.springboot_demo.service.GoodsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <P> @Author: SongKeCheng
 * <P> Type: Class
 * <P> Description:
 * <P> Date: 2024/9/4:9:10
 */

@SuppressWarnings({"unchecked", ""})
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements GoodsService {
    @Autowired
    private GoodsMapper goodsMapper;


    @Override
    public List<Goods> findGoods(Integer id, String author, String name) {


        QueryWrapper<Goods> goodsQueryWrapper = new QueryWrapper<>();
        if (id != null) {
            goodsQueryWrapper.eq("id", id);
        }
        if (StringUtils.isNotEmpty(author)) {
            goodsQueryWrapper.like("author", author);
        }

        goodsQueryWrapper.like(StringUtils.isNotEmpty(name), "name", name);
        //List<Goods> goods = goodsMapper.selectList(goodsQueryWrapper);
        List<Goods> goods =  goodsMapper.selectListByCondition(id, author, name);
        return goods;
    }
}
